package cn.pengyinrui.pethome.emp.controller;

import cn.pengyinrui.pethome.base.controller.BaseController;
import cn.pengyinrui.pethome.dept.query.DepartmentQuery;
import cn.pengyinrui.pethome.emp.domain.Employee;
import cn.pengyinrui.pethome.emp.query.EmployeeQuery;
import cn.pengyinrui.pethome.emp.service.IEmployeeService;
import cn.pengyinrui.pethome.utils.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/emp")
// 对controller做描述
@Api(value = "部门的API",description = "部门相关的CRUD功能")
public class EmployeeController {
    @Autowired
    private IEmployeeService service;

    //@RequestMapping(value = "list",method = RequestMethod.GET)
    @GetMapping("/list")
    // 对方法做描述
    @ApiOperation(value = "查询全部的员工")
    public AjaxResult findAll(){
        try {
            return AjaxResult.success()
                    .setData(service.findAll());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.error();
    }


    @PostMapping("/query")
    @ApiOperation(value = "分页查询")
    public AjaxResult findAllByQuery(@RequestBody EmployeeQuery query){
        try {
            return AjaxResult.success()
                    .setData(service.findAllByQuery(query))
                    .setTotal(service.findAllByQueryCount(query));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.error();
    }

}
